package com.save.rpgsavedecode.service;

import com.save.rpgsavedecode.entry.FileEntry;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

@Service
public class FileReadService {


    public List<FileEntry> getFiles(String path) throws FileNotFoundException {
        List<FileEntry> fileEntryList = new ArrayList<>();
        File file = new File(path);
        File[] files = file.listFiles();
        for (File f: files) {
            if (f.isFile()) {
                FileInputStream fileStream = new FileInputStream(f);
                FileEntry fileEntry = new FileEntry(f.getName(), f.getAbsolutePath());
                fileEntryList.add(fileEntry);
            }
        }
        return fileEntryList;
    }
}
